package com.leyou.item.controller;


import com.leyou.item.dto.CategoryDTO;
import com.leyou.item.service.TbCategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 * 商品类目表，类目和商品(spu)是一对多关系，类目与品牌是多对多关系 前端控制器
 * </p>
 *
 * @author HM
 * @since 2021-06-16
 */
@RestController
@RequestMapping("/category")
public class TbCategoryController {

    @Autowired
    private TbCategoryService categoryService;

    /**
     * 根据父id 获取分类集合
     * @param pid
     * @return
     */
    @GetMapping("/of/parent")
    public ResponseEntity<List<CategoryDTO>> findByParentId(@RequestParam(name = "pid") Long pid){

        List<CategoryDTO> categoryDTOS = categoryService.queryListByParentId(pid);

        return ResponseEntity.ok(categoryDTOS);
    }

    /**
     * 查询品牌所属的分类信息
     * @param brandId
     * @return
     */
    @GetMapping("/of/brand")
    public ResponseEntity<List<CategoryDTO>> findCategoryListByBrandId(@RequestParam(name = "id") Long brandId){
        List<CategoryDTO> ca = categoryService.findCategoryListByBrandId(brandId);
        return ResponseEntity.ok(ca);
    }

}

